package com.ren.service.core.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ren.service.core.mapper.UserLoginRecordMapper;
import com.ren.service.core.model.po.UserLoginRecordPO;
import com.ren.service.core.model.vo.UserLoginRecordRespVO;
import com.ren.service.core.service.IUserLoginRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author RenGaoshuai
 * @date 2023/8/9 9:54
 * @description
 */
@Service
public class UserLoginRecordServiceImpl implements IUserLoginRecordService {

    @Autowired
    private UserLoginRecordMapper userLoginRecordMapper;

    @Override
    public List<UserLoginRecordRespVO> listTop50(Long userId) {
        LambdaQueryWrapper<UserLoginRecordPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLoginRecordPO::getUserId, userId)
                .eq(UserLoginRecordPO::getDeleted, false)
                .orderByDesc(UserLoginRecordPO::getId)
                .last("limit 50");
        List<UserLoginRecordPO> poList = userLoginRecordMapper.selectList(wrapper);
        return BeanUtil.copyToList(poList, UserLoginRecordRespVO.class);

    }
}
